<?php

session_start();
include_once 'classControleur.php';
var_dump($_POST);
if (!empty($_POST)) {
    $password = "";
    if (isset($_POST['password'])) {
        $password = $_POST['password'];
    }
    $Apassword = "";
    if (isset($_POST['lastPassword'])) {
        $Apassword = $_POST['lastPassword'];
    }
    $password2 = "";
    if (isset($_POST['password2'])) {
        $password2 = $_POST['password2'];
    }

    $SQLBlog = new SQLBlog();
    $utilisateurDonnee = $SQLBlog->AfficherDonneesUtilisateurs($_SESSION['id']);
    var_dump($utilisateurDonnee);
    $controleur = new classControleur();
    $messageEpassword = $controleur->testPassword($password);
    $AmessageEpassword = $controleur->testPassword($Apassword);
    $messageEpassword2 = $controleur->testPassword($password2);

    if (strcmp($utilisateurDonnee[0]['motDePasse'], $Apassword) != 0) {
        $AmessageEpassword = "le mot de passe n'est pas bon";
        $controleur->setErreur(true);
    }

    if (strcmp($password2, $password) != 0) {
        $controleur->setErreur(true);
        $messageEpassword = "les 2 mots de passe sont differents";
        $messageEpassword2 = "les 2 mots de passe sont differents";
    }



    if ($controleur->getErreur() == false) {
        $SQLBlog->MAJMotDePasseUtilisateur($password, $_SESSION['id']);
        header("Location:../vue/gestionUtilisateur.php?successMDP=1");
    } else {
        header("Location:../vue/gestionUtilisateur.php?messageEPassword=$messageEpassword&messageEpassword2=$messageEpassword2&messageEpasswordLast=$AmessageEpassword");
    }
}
?>